package com.github.pig.training.util;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.apache.poi.ss.formula.functions.T;

import java.util.HashMap;
import java.util.Map;

public class Query {
    private static String[] dictionaries = { "label", "intention_level", "working_area" };
    private static EntityWrapper entityWrapper = null;

    public static Map<String,Object> getEntityWrapperByCondition (EntityWrapper ew,Map<String,Object> map) {
        if (ew != null) {
            entityWrapper = ew;
        } else {
            entityWrapper = new EntityWrapper<>();
        }

        for (String str : dictionaries) {
            if (map != null && map.get(str) != null && map.get(str).toString().length() > 0) {
                String[] strs = map.get(str).toString().split(",");
                String sql = "(";
                for (int i = 0, len = strs.length; i < len; i++) {
                    sql += str + " like '%" + strs[i] + "%' OR ";
                }
                sql = sql.substring(0, (sql.length() - 3));
                entityWrapper.and(sql + ")");
                map.remove(str);
            }
        }

        Map<String,Object> map1 = new HashMap<>();
        map1.put("entityWrapper",entityWrapper);
        map1.put("map",map);
        return map1;
    }
}
